/**
 * 
 */
package br.com.ufrn.aipetro.ga.controller.device;

import java.util.List;

import br.com.ufrn.aipetro.ga.domain.entity.device.OperationStatus;
import br.com.ufrn.aipetro.ga.domain.entity.device.Protocol;
import br.com.ufrn.aipetro.ga.domain.entity.device.actuator.valve.Valve;
import br.com.ufrn.aipetro.ga.domain.entity.mesh.Mesh;
import br.com.ufrn.aipetro.ga.domain.entity.plant.Plant;
import br.com.ufrn.aipetro.ga.domain.entity.unit.Unit;
import br.com.ufrn.aipetro.ga.persist.interfaces.DaoFactory;

/**
 * @author Lucas
 *
 */
public class ValveController extends DeviceController<Valve> {
	
	DaoFactory daoFactory;
	
	public ValveController(DaoFactory factory) {
		this.daoFactory = factory;
		setModel(new Valve());
	}
	
	public void changeHysteresis(float hysteresis) {
		getModel().setHysteresis(hysteresis);
	}

	public void changeRangeability(float rangeability) {
		getModel().setRangeability(rangeability);
	}
	
	public void changeTemperatureCurrent(float temperatureCurrent) {
		getModel().setTemperatureCurrent(temperatureCurrent);
	}
	public void changeTemperatureMin(float temperatureMin) {
		getModel().setTemperatureMin(temperatureMin);
	}
	public void changeTemperatureMax(float temperatureMax) {
		getModel().setTemperatureMax(temperatureMax);
	}
	public void changeDeadBand(float deadBand) {
		getModel().setDeadBand(deadBand);
	}
	public void changeTimeToOpening(float timeToOpening) {
		getModel().setTimeToOpening(timeToOpening);
	}
	public void changeTimeToClosing(float timeToClosing) {
		getModel().setTimeToClosing(timeToClosing);
	}
	public void changePositionerValue(float positionerValue) {
		getModel().setPositionerValue(positionerValue);
	}
	public void changeFriction(float friction) {
		getModel().setFriction(friction);
	}
	public void changePressureInlet(float pressureInlet) {
		getModel().setPressureInlet(pressureInlet);
	}
	
	public void changePressureOutlet(float pressureOutlet) {
		getModel().setPressureOutlet(pressureOutlet);
	}

	public void changePressureMaxAbs(float pressureMaxAbs) {
		getModel().setPressureMaxAbs(pressureMaxAbs);
	}
	
	public void changePressureMaxDifferential(float pressureMaxDifferential) {
		getModel().setPressureMaxDifferential(pressureMaxDifferential);
	}
	
	public void changeFlowRate(float flowRate) {
		getModel().setFlowRate(flowRate);
	}
	
	public void persistInsert() {
		daoFactory.beginTransaction();
		daoFactory.createValveDao().insert(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistUpdate() {
		daoFactory.beginTransaction();
		daoFactory.createValveDao().update(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistDelete(Valve controller) {
		daoFactory.beginTransaction();
		daoFactory.createValveDao().delete(controller);
		daoFactory.commitTransaction();
	}
	
	public List<Valve> persistSearchAll() {
		daoFactory.beginTransaction();
		List<Valve> valveList = daoFactory.createValveDao().searchAll();
		daoFactory.commitTransaction();
		return valveList;
	}
	
	public List<OperationStatus> persistSearchAllOperationStatus() {
		daoFactory.beginTransaction();
		List<OperationStatus> listOperationStatus = daoFactory.createOperationStatusDao().searchAll();
		daoFactory.commitTransaction();
		return listOperationStatus;
	}
	
	public List<Protocol> persistSearchAllProtocol() {
		daoFactory.beginTransaction();
		List<Protocol> listProtocol = daoFactory.createProtocolDao().searchAll();
		daoFactory.commitTransaction();
		return listProtocol;
	}
	
	public List<Unit> persistSearchAllUnit() {
		daoFactory.beginTransaction();
		List<Unit> listUnit = daoFactory.createUnitDao().searchAll();
		daoFactory.commitTransaction();
		return listUnit;
	}
	
	public List<Plant> persistSearchPlantByUnit(Unit unit) {
		daoFactory.beginTransaction();
		List<Plant> listPlant = daoFactory.createPlantDao().searchByUnit(unit);
		daoFactory.commitTransaction();
		return listPlant;
	}
	
	public List<Mesh> persistSearchMeshByPlant(Plant plant) {
		daoFactory.beginTransaction();
		List<Mesh> listMesh = daoFactory.createMeshDao().searchByPlant(plant);
		daoFactory.commitTransaction();
		return listMesh;
	}
	
	public List<Valve> persistSearchByExample(Valve example) {
		daoFactory.beginTransaction();
		List<Valve> valveList = daoFactory.createValveDao().searchByExample(example);
		daoFactory.commitTransaction();
		return valveList;
	}

}
